# -*- coding: utf-8 -*-

"""
Module implementing ConfigDialog.
"""
import sys, os
parpath=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(parpath)

from config import INI

from PyQt4.QtGui import QDialog
from PyQt4.QtCore import pyqtSignature

from Ui_ConfigDlg import Ui_ConfigDialog

class ConfigDialog(QDialog, Ui_ConfigDialog):
    """
    配置对话框
    """
    def __init__(self, parent = None):
        """
        Constructor
        """
        QDialog.__init__(self, parent)
        self.setupUi(self)
        
        #载入各设置
        self.lineName.setText(INI.player.name)
        self.ckInitReady.setChecked(INI.player.initReady)
        self.ckInitUseAi.setChecked(INI.player.initUseAi)
        self.sbAiTime.setValue(INI.player.aiTime)
        self.sbTakeTime.setValue(INI.player.takeTime)
        
        self.sbListenTime.setValue(INI.server.listenTime)
        self.sbWaitTime.setValue(INI.server.waitTime)
        self.sbRecvTime.setValue(INI.client.recvTime)
        
        self.ckTakeCard.setChecked(INI.gui.takeCardAm)
        self.ckPlayCard.setChecked(INI.gui.playCardAm)
        self.sbTakeCardTime.setValue(INI.gui.takeCardTime)
        self.sbPlayCardTime.setValue(INI.gui.playCardTime)
        
    def accept(self):
        '''槽，确定按钮的响应'''
        #保存各设置
        INI.player.name=self.lineName.text()
        INI.player.initReady=self.ckInitReady.isChecked()
        INI.player.initUseAi=self.ckInitUseAi.isChecked()
        INI.player.aiTime=self.sbAiTime.value()
        INI.player.takeTime=self.sbTakeTime.value()
        
        INI.server.listenTime=self.sbListenTime.value()
        INI.server.waitTime=self.sbWaitTime.value()
        INI.client.recvTime=self.sbRecvTime.value()
        
        INI.gui.takeCardAm=self.ckTakeCard.isChecked()
        INI.gui.playCardAm=self.ckPlayCard.isChecked()
        INI.gui.takeCardTime=self.sbTakeCardTime.value()
        INI.gui.playCardTime=self.sbPlayCardTime.value()
        
        INI.save()
        
        QDialog.accept(self)
